<?php

error_reporting(E_ALL);
ini_set('display_errors', 1);

/*
 * do basic housekeeping tasks
 */

require_once('admin.php');

$title = __('Options','lp');
$this_file = 'lightpress/wp-plugin/options.php';
$parent_file = 'lightpress/wp-plugin/main.php';

$submenu[$this_file][] = array('LightPress', 'manage_options', 'lightpress/wp-plugin/options.php', 'LightPress');

/*
 * instantiate LightPressOptions and the Template object
 */

if (!isset($lp_opts)) {
    require_once 'LightPressOptions.php';
    $lp_opts = new LightPressOptions();
} else if (!is_object($lp_opts) || !is_subclass_of($lp_opts, 'LightPressOptions')) {
    $lp_opts = new LightPressOptions();
}

require_once implode(DIRECTORY_SEPARATOR, array(dirname(dirname(__FILE__)), 'classes', 'Template.php'));
$tpl =& new Template(implode(DIRECTORY_SEPARATOR, array(dirname(__FILE__), 'templates-'.__('en_US','lp'))));

$tpl->setFile('main', 'options.html');

$opts = array_merge($lp_opts->critical, array_keys($lp_opts->base));

$tpl_vars = array();

if (isset($_POST['submit'])) {
    foreach ($opts as $opt) {
        if (isset($_POST["lp_opt_$opt"]))
            $lp_opts->updateOption("lp_opt_$opt", $_POST["lp_opt_$opt"]);
    }
} else {
    $tpl->setBlock('main', 'message', 'MESSAGE');
    $tpl_vars['MESSAGE'] = '';
}

foreach ($opts as $opt) {
    $value = $lp_opts->getOption($opt);
    if (is_string($value)) {
        if ($opt != 'basedir')
            $value = htmlspecialchars(stripslashes($value));
        else
            $value = htmlspecialchars($value);
    }
    $tpl_vars[$opt] = $value;
}
// set options for select lists
$tpl_vars['lp_opt_mail_mailer_qmail'] = '';
if ($lp_opts->getOption('mail_mailer') == 'qmail')
    $tpl_vars['lp_opt_mail_mailer_qmail'] = ' selected';
$tpl_vars['lp_opt_comment_spam_kill_kill'] = '';
if ($lp_opts->getOption('comment_spam_kill') == '1')
    $tpl_vars['lp_opt_comment_spam_kill_kill'] = ' selected';
$tpl_vars['lp_opt_comment_spam_mail_ignore'] = '';
if ($lp_opts->getOption('comment_spam_mail') != '1')
    $tpl_vars['lp_opt_comment_spam_mail_ignore'] = ' selected';
 


$tpl->setVar($tpl_vars);

$out =& $tpl->parse('MAIN', 'main');
echo $out;

?>
